﻿using System;
using System.ComponentModel;
using System.Drawing;
using System.Windows.Forms;

namespace YJKDataLookAfter
{
	public partial class DlgRemoveRole : System.Windows.Forms.Form
	{
		public DlgRemoveRole(string group)
		{
			this.mGroup = group;
			this.InitializeComponent();
		}

		private void btnRemove_Click(object sender, EventArgs e)
		{
			if (this.lbxRole.SelectedItem != null)
			{
				try
				{
					DbRole dbRole = (DbRole)this.lbxRole.SelectedItem;
					if (dbRole.Name == "系统管理员")
					{
						MessageBox.Show("无法删除管理员职位！");
					}
					else
					{
						dbRole.RemoveFromDb();
						this.lbxRole.Items.RemoveAt(this.lbxRole.SelectedIndex);
						if (this.lbxRole.Items.Count > 0)
						{
							this.lbxRole.SelectedIndex = 0;
						}
					}
				}
				catch (Exception ex)
				{
					MessageBox.Show(ex.Message);
				}
			}
		}

		private void DlgRemoveRole_Load(object sender, EventArgs e)
		{
			try
			{
				foreach (DbRole item in DbRole.GetAllRoles(BimServerDB.Default, this.mGroup))
				{
					this.lbxRole.Items.Add(item);
				}
				if (this.lbxRole.Items.Count > 0)
				{
					this.lbxRole.SelectedIndex = 0;
				}
			}
			catch (Exception ex)
			{
				MessageBox.Show(ex.Message);
			}
		}

		private void btnCancel_Click(object sender, EventArgs e)
		{
			base.Close();
		}

		private string mGroup = "";
	}
}
